-
-
Notifications
You must be signed in to change notification settings - Fork 540
Build packages with unbuild to improve CJS support #2310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: a340c6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for openapi-ts canceled.
|
size-limit report 📦
|
4799af3
to
f375ba6
Compare
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/index.d.cts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With separate .d.cts
and .d.mts
declarations generated, we don’t need to declare types
separately. This was a little bit of a hack from previous builds that stuck around. With unbuild’s better generation in general, TypeScript can automatically locate types.
@@ -8,19 +8,12 @@ | |||
}, | |||
"license": "MIT", | |||
"type": "module", | |||
"main": "./dist/index.js", | |||
"module": "./dist/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"module"
has never been standardized, but was just a common community convention—common enough it started to sneak into some bundle setups. All Node LTS versions and all bundlers I’m aware of now respect "exports"
, which means this is no longer needed.
"main"
is still standard. And technically it’s superceded by exports
, but we’ll just keep it around for safety. But "module"
is safe to remove at this point.
@@ -8,19 +8,12 @@ | |||
}, | |||
"license": "MIT", | |||
"type": "module", | |||
"main": "./dist/index.js", | |||
"module": "./dist/index.js", | |||
"types": "./dist/index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for "types"
—at this point TypeScript can now just locate the types due to unbuild’s careful handling
}, | ||
"./*.js": "./*.mjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unbuild intentionally ships .mjs
so there’s no ambiguity about the .js
files being ESM, and there’s no way to opt out of this behavior. While in our case we’ve been shipping ESM for a while, I still agree in general—.js
files is a bit of a clusterfuck trying to sniff out package.json
s to know how to parse it.
This is encroaching on a breaking change for this library, but I’m just considering it a minor version because:
- Deep imports have never had a strict guarantee they’ll be preserved perfectly
- This extension rewriting should preserve
.js
imports as-authored - We’re still building files 1:1 to their original versions, just with
.mjs
extensions, so even if a setup does break it’s a mild annoyance not a show-stopper
cef463a
to
5772987
Compare
"test:js": "vitest run", | ||
"test:ts": "tsc --noEmit", | ||
"test:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json", | ||
"test:exports": "pnpm run build && attw --pack .", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the “are the types wrong” type tests, so added to all packages. We were also able to remove the cjs-resolves-to-esm
rule 😎
@@ -1,4 +1,5 @@ | |||
.turbo | |||
*.config.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore build.config.ts
configs for unbuild in package publishing
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
// Don’t bundle .js files together to more closely match old exports (can remove in next major) | ||
output: { preserveModules: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openapi-metadata was already using unbuild! But adding this config just shores it up more closely with the other packages without changing output too much.
Merging this not to bulldoze anyone; this is just a very unopinionated PR that is just package maintenance. The change does require a version-bump just to guard against accidental regressions, but anything that crops up is fixable/changeable. Overall this should be a net win for everybody, improving CJS support and build quality. |
* Update schema-object.ts * chore(deps): update dependency msw to v2.7.6 (openapi-ts#2287) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @types/node to v22.15.10 (openapi-ts#2293) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @shikijs/vitepress-twoslash to v3.4.0 (openapi-ts#2298) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @arethetypeswrong/cli to ^0.18.0 (openapi-ts#2272) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency execa to v9.5.3 (openapi-ts#2303) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(metadata): fix thunk type detection (openapi-ts#2125) * Don't remove `null` type if a default is present. (openapi-ts#2145) * Don't remove `null` type if a default is present. * Don't remove `null` type from enums if default is present. * Don't remove `null` type if default is present (legacy) * [ci] release (openapi-ts#2307) * [ci] release * Add 2145 manually --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * chore(deps): update dependency @types/react to v18.3.21 (openapi-ts#2218) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(openapi-fetch): fix overriding baseUrl per request without overriding default baseUrl (openapi-ts#2157) * Support $ref into `paths` (openapi-ts#2185) * React query handle 204 or zero content length (openapi-ts#2235) * fix(openapi-react-query): Handle 204 or zero Content-Length header by returning data as null * fix(openapi-react-query): updated and added 204 & zero Content-Length queryFn tests * chore(openapi-react-query): Fixed linting in test * chore(deps): update dependency @arethetypeswrong/cli to v0.18.1 (openapi-ts#2306) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency msw to v2.8.2 (openapi-ts#2304) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Speakeasy URL (openapi-ts#2302) * chore(deps): update dependency @tanstack/react-query to v5.75.7 (openapi-ts#2301) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency lint-staged to v15.5.2 (openapi-ts#2297) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * feat(swr-openapi): add custom error types to query builder (openapi-ts#2147) * chore(deps): update vitest monorepo to v3 (openapi-ts#2284) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Encode the request body if Content-Type set (openapi-ts#2096) * Improve header handling (openapi-ts#2308) * [ci] release (openapi-ts#2309) * [ci] release * Release additional packages --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * chore: update openapi-fetch test fixture (openapi-ts#2313) * Build packages with unbuild to improve CJS support (openapi-ts#2310) * [ci] release (openapi-ts#2314) * [ci] release * Fix major bump --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * Update code of conduct source (openapi-ts#2316) Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com> --------- Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Martin Paucot <contact@martin-paucot.fr> Co-authored-by: Theron Luhn <theron@luhn.com> Co-authored-by: openapi-ts-bot <openapi-ts@googlegroups.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> Co-authored-by: Luis Merino <mail@luismerino.name> Co-authored-by: Duncan Beevers <duncan@dweebd.com> Co-authored-by: Wheelebin <wheelebin@users.noreply.github.com> Co-authored-by: Nolan Di Mare Sullivan <nolan.dm.sullivan@gmail.com> Co-authored-by: しゅーまい <62363188+SSlime-s@users.noreply.github.com> Co-authored-by: Olga Bulat <obulat@gmail.com> Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Changes
Unbuild is a fantastic packaging system that is the best available in my opinion. Build all our packages with it to reduce maintenance and overhead, and improve support. It’s still ESM-first, so there should be no changes to runtime, client weight, or bundlesize downstream, and only improves stability and support.
This also aligns openapi-typescript, openapi-fetch, openapi-react-query, and swr-openapi to all be built the same way.
If this causes any issues, please file an issue! Anything that crops up is fixable with the Unbuild system because it’s based on Rollup.
How to Review
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)